#include "base/Simulator.h"
#include "base/TrapGenerator.h"
#include "base/signals/SigManager.h"

NEW_DELETE_OPERATORS_CPP(TrapGenerator,100);
static Pool* TrapGeneratorMContextPool = 
    NEW Pool("TrapGeneratorMContextPool",
#ifdef __APPLE__
             sizeof(struct mcontext),
#else
#ifdef __linux__
             sizeof(mcontext_t),
#else
#ifdef _AIX
             // Garbage value
             sizeof(void*),
#else
#error unsupported OS
#endif
#endif
#endif
             10,
             Pool::CACHE_LINE_PADDING,
             false);

TrapGenerator::TrapGenerator()
{
    signum        = SIGSEGV;
    info.si_signo = SIGSEGV;
    context.uc_link = NULL;
}

TrapGenerator::~TrapGenerator ()
{
}

void TrapGenerator::generateTrap ()
{
    signalLog->i("[TrapGenerator] trap is generated\n");
    global_sim->getSM()->invokeSignalHandler(signum, &info, &context);
}
